pub fn odd_fibnacci_sum(threshold: u32) -> u32 {
    let mut generator = FibGenerator::default();
    1 + (0..)
        .map(|_| generator.next())
        .take_while(|&x| x < threshold)
        .filter(|&x| x & 0b1 == 1)
        .sum::<u32>()
}

struct FibGenerator {
    a: u32,
    b: u32,
}

impl Default for FibGenerator {
    fn default() -> Self {
        Self { a: 0, b: 1 }
    }
}

impl FibGenerator {
    fn next(&mut self) -> u32 {
        let c = self.a + self.b;
        self.a = self.b;
        self.b = c;
        c
    }
}
